
import { customRef } from 'vue'
export default (value, delay = 200) => {
    let timeout
    return customRef((track, trigger) => {
        return {
            get () {
                //依赖收集
                track()
                return value
            },
            set (val) {
                clearTimeout(timeout)
                timeout = setTimeout(() => {
                    // 派发更新
                    value = val;
                    trigger()
                }, delay)
            }
        }
    })
}